package com.mia.props.client.fx;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.material.Material;
import net.minecraft.client.particle.EntityFX;
import net.minecraft.world.World;

@SideOnly(Side.CLIENT)
public class EntityCustomRainFX extends EntityFX {
   private Material materialType;

   public EntityCustomRainFX(World par1World, double par2, double par4, double par6, float size) {
      super(par1World, par2, par4, par6);
      this.particleAlpha = 1.0F;
      this.setSize(0.01F, 0.01F);
      this.yOffset = this.height / 2.0F;
      this.setPosition(par2, par4, par6);
      this.lastTickPosX = par2;
      this.lastTickPosY = par4;
      this.lastTickPosZ = par6;
      this.particleTextureJitterX = this.rand.nextFloat() * 3.0F;
      this.particleTextureJitterY = this.rand.nextFloat() * 3.0F;
      this.particleScale = (this.rand.nextFloat() * 0.5F + 0.5F) * 2.0F;
      this.particleRed = 0.2F;
      this.particleGreen = 0.3F;
      this.particleBlue = 1.0F;
      this.particleGravity = 0.06F;
      this.particleMaxAge = (int)(64.0D / (Math.random() * 0.8D + 0.2D));
      this.particleAge = 0;
      this.particleScale *= size;
   }

   public int getBrightnessForRender(float par1) {
      return this.materialType == Material.water ? super.getBrightnessForRender(par1) : 257;
   }

   public float getBrightness(float par1) {
      return this.materialType == Material.water ? super.getBrightness(par1) : 1.0F;
   }

   public void onUpdate() {
      this.prevPosX = this.posX;
      this.prevPosY = this.posY;
      this.prevPosZ = this.posZ;
      this.motionY -= (double)this.particleGravity;
      this.setParticleTextureIndex(112);
      this.moveEntity(0.0D, this.motionY, 0.0D);
      if (this.particleMaxAge-- <= 0) {
         this.setDead();
      }

      if (this.onGround) {
         this.setDead();
         this.worldObj.spawnParticle("splash", this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D);
         this.motionX *= 0.699999988079071D;
         this.motionZ *= 0.699999988079071D;
      }

   }
}
